package com.erbao.dp.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CaoBaoYin
 * @since 2021/9/13 21:12
 */
public class Main05 {
    public static void main(String[] args) {
        Child child = new Child();

        child.wakeup();
    }

    interface Observer{
        void actionOnWakeUp();
    }

    static class Dad implements Observer {
        public void feed(){
            System.out.println(" dad feeding .......");
        }

        @Override
        public void actionOnWakeUp() {
            feed();
        }
    }

    static class Mom implements Observer {
        public void hug(){
            System.out.println(" mom hugging ......");
        }

        @Override
        public void actionOnWakeUp() {
            hug();
        }
    }

    static class Dog implements Observer{
        public void wang(){
            System.out.println(" dog wang......");
        }

        @Override
        public void actionOnWakeUp() {
            wang();
        }
    }

    static class Child {
        private boolean cry = false;
        private List<Observer> observerList = new ArrayList<>();

        {
            observerList.add(new Dad());
            observerList.add(new Mom());
            observerList.add(new Dog());
        }

        public boolean isCry() {
            return cry;
        }

        public void wakeup() {
            System.out.println("wake up ! wuwuuwuwuu……");
            cry = true;
            for (Observer observer : observerList) {
                observer.actionOnWakeUp();
            }
        }
    }
}
